import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_deer/generated/json/base/json_field.dart';
import 'package:flutter_deer/generated/json/card_list_bean_entity.g.dart';

export 'package:flutter_deer/generated/json/card_list_bean_entity.g.dart';

@JsonSerializable()
class CardListBeanEntity {
	String accountBalance = '';
	String accountBalanceInfo = '';
	String accountCode = '';
	String accountStatus = '';
	String accountType = '';
	String allocationBalance = '';
	String allocationBalanceInfo = '';
	String belongMchCode = '';
	String belongMchType = '';
	String cardName = '';
	String cardNo = '';
	int cardNoStatus = 0;
	String categoryId = '';
	String categoryName = '';
	String categorySubId = '';
	String categorySubName = '';
	String createTime = '';
	bool enableBuyExcludeOil = false;
	String entityType = '';
	String giftBalance = '';
	String giftBalanceInfo = '';
	String id = '';
	int isGroupUse = 0;
	int isSubRecharge = 0;
	String mchCode = '';
	String mchName = '';
	String mchNames = '';
	String prepayCardTemplateId = '';
	String rechargeBalance = '';
	String rechargeBalanceInfo = '';
	String templateRechargeStatus = '';
	List<dynamic> useMchCodes = [];

	CardListBeanEntity();

	factory CardListBeanEntity.fromJson(Map<String, dynamic> json) => $CardListBeanEntityFromJson(json);

	Map<String, dynamic> toJson() => $CardListBeanEntityToJson(this);

	@override
	String toString() {
		return jsonEncode(this);
	}

	String get showCardNo => cardNo.isNotEmpty ? cardNo : accountCode;

	String get typeName => getTypeName(accountType, entityType, belongMchType);

  String getTypeName(String accountType, String entityType, String belongMchType) {
    if (belongMchType == 'group_mch') {
      return '集团卡';
    }
    if (accountType == 'INDIVIDUAL') {
      return '个人卡';
    }
    if (accountType == 'ENTERPRISE') {
      return entityType == 'AGREEMENT_COMPANY' ? '企业主卡' : '企业子卡';
    }
    if (accountType == 'GIFT_CARD') {
      return '礼品卡';
    }
    return '';
  }

	// 根据卡类型和卡状态获取颜色
	Color get cardColor {
		if (accountStatus != 'NORMAL') {
      return Colors.grey;
    }
    switch (typeName) {
      case '个人卡':
        return Colors.teal;
      case '企业主卡':
        return Colors.black;
      case '企业子卡':
        return Colors.black;
      case '礼品卡':
        return Colors.purple;
      default:
        return Colors.grey;
    }
  }

	//状态
	String get statusName => getStatusName();

  String getStatusName() {
    switch (accountStatus) {
      case 'FREEZE':
        return '已冻结';
      case 'CANCEL':
        return '已注销';
      case 'NORMAL':
        return '';
      default:
        return accountStatus;
    }
  }
}